Promise.prototype.myAll = function (...args) {
    let result = []
    new Promise(function (resolve, reject) {
        for (let i = 0; i < args.length; i++) {
            args[i]().then(res => {
                result[i] = res // 优先
                if (result.length == args.length) {
                    return resolve(result)
                }
            }).catch(err => {
                reject(err)
            })
        }
    }, function (err) {
        reject(err)
    })
}

Promise.prototype.myRace = function (...args) {

    new Promise(function (resolve, reject) {
        for (let i = 0; i < args.length; i++) {
            args[i]().then(res => {
                return resolve(res)
            }).catch(err => {
                reject(err)
            })
        }
    }, function (err) {
        reject(err)
    })
}


Promise.prototype.finally = function (callback) {
    let P = this.constructor;
    return this.then(
      value  => P.resolve(callback()).then(() => value),
      reason => P.resolve(callback()).then(() => { throw reason })
    );
  };